package com.tidc.seaserverservice.aspect;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.tidc.seaservermapper.dao.RabbitMessageLogDao;
import com.tidc.seaservermodel.entity.RabbitMessageLog;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author ：冯涛滔
 * @date ：Created in 2020/10/28 16:05
 * @description：
 * @modified By：
 * @version:
 */
@Aspect
@Component
@Slf4j
public class RabbitAspect {
    @Resource
    private RabbitMessageLogDao rabbitMessageLogDao;
    @Resource
    private ObjectMapper objectMapper;
    @Pointcut("execution(void com.tidc.seaserverservice.util.RabbitUtil.sendMQ(..))")
    public void affected() {}

    @Before(value = "affected()")
    public void doBefore(JoinPoint joinPoint) throws Throwable {
        Object[] args = joinPoint.getArgs();

        RabbitMessageLog rabbitMessageLog = (RabbitMessageLog) args[0];
        RabbitMessageLog check = rabbitMessageLogDao.queryByMsgId(rabbitMessageLog.getMsgId());
        if(check == null){
            rabbitMessageLogDao.insert(rabbitMessageLog);
        }
    }

}
